package com.hnl.core;

import java.util.Locale;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.timer.HNLSOLRTasksTimerInitializer;

@SuppressWarnings("serial")
public class HNLCore extends HttpServlet {
	public static final Logger LOG = LoggerFactory.getLogger(HNLCore.class);

	public static final String DEFAULT_CONF_FILE = "WEB-INF/hnlconfig.xml";

	private static HNLConfig hnlConfig;

	@Override
	public void init(ServletConfig config) throws ServletException {
		// set locale to EN
		Locale.setDefault(Locale.ENGLISH);

		// initialize HNM config
		hnlConfig = HNLConfig.getInstance(config.getServletContext()
				.getResourceAsStream(DEFAULT_CONF_FILE));

		HNLDBInitializer.initDB();
		HNLSOLRTasksTimerInitializer.initHNLSOLRTasksTimer();
		HNLAttachmenInitializer.initAttachment();

		LOG.info("HNL Core Loaded Successfully!");
	}

	public static Config getHNLConfig() {
		return hnlConfig;
	}
}
